
#include "util.h"
#include "InterpretClosure.h"
#include "CodeMethod.h"
#include "InterpretPrescription.h"

Object* InterpretClosure::execute(Image* image,int argc,Object** argv){
    map<string,Object*> temps=context;
    if(argc!=prescription->args.size()){
        printf("ERROR: arguments count does not match in closure");
    }
    for(int i=0;i<prescription->args.size();i++){
        temps[prescription->args[i].name]=argv[i];
    }
    for(int i=0;i<prescription->code.size();i++){
        Object* res=execute_stmt(prescription->code[i],image,self,&temps);
        if(res!=NULL) return res;
    }
    return NULL;
}
